﻿@namespace Blazorise.Docs.Docs.Examples

<DataGrid TItem="Employee"
          Data="@employeeList"
          FixedColumns
          ShowPager
          ShowPageSizes
          @bind-SelectedRow="@selectedEmployee">
    <DataGridColumns>
        <DataGridColumn TextAlignment="TextAlignment.Center" TItem="Employee" Field="@nameof( Employee.Id )" Caption="#" Width="60px" FixedPosition="TableColumnFixedPosition.Start" />
        <DataGridColumn TItem="Employee" Field="@nameof( Employee.FirstName )" Caption="First Name" Width="150px" />
        <DataGridColumn TItem="Employee" Field="@nameof( Employee.LastName )" Caption="Last Name" Width="150px" />
        <DataGridColumn TItem="Employee" Field="@nameof( Employee.Email )" Caption="Email" Width="250px" FixedPosition="TableColumnFixedPosition.Start" />
        <DataGridColumn TItem="Employee" Field="@nameof( Employee.City )" Caption="City" Width="150px" />
        <DataGridColumn TItem="Employee" Field="@nameof( Employee.Zip )" Caption="Zip" Width="100px" />
        <DataGridDateColumn TItem="Employee" Field="@nameof( Employee.DateOfBirth )" DisplayFormat="{0:dd.MM.yyyy}" Caption="Date Of Birth" Width="100px" />
        <DataGridNumericColumn TItem="Employee" Field="@nameof( Employee.Childrens )" Caption="Childrens" Filterable="false" Width="100px" />
        <DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Gender )" Caption="Gender" Data="EmployeeData.Genders" ValueField="(x) => ((Gender)x).Code" TextField="(x) => ((Gender)x).Description" Width="100px" />
        <DataGridColumn TItem="Employee" Field="@nameof( Employee.Salary )" Caption="Salary" DisplayFormat="{0:C}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" TextAlignment="TextAlignment.End" Width="100px" FixedPosition="TableColumnFixedPosition.End" />
        <DataGridCheckColumn TItem="Employee" Field="@nameof(Employee.IsActive)" Caption="Active" Filterable="false" Width="100px" />
    </DataGridColumns>
</DataGrid>

@code {
    [Inject]
    public EmployeeData EmployeeData { get; set; }
    private List<Employee> employeeList;
    private Employee selectedEmployee;

    protected override async Task OnInitializedAsync()
    {
        employeeList = await EmployeeData.GetDataAsync();
        await base.OnInitializedAsync();
    }
}